package Junit4;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class SaleMachineTest2 {
    private SaleMachine saleMachine;

    @Before
    public void setUp() throws Exception {
        saleMachine = new SaleMachine(1,1,1,1);
    }

    @After
    public void tearDown() throws Exception {
        saleMachine = new SaleMachine();
    }
    @Test
    public void testOperation1(){
        saleMachine.operation("Beer","5J");
    //投币5角，选择啤酒，啤酒剩余，期望值为啤酒数-1,5角数+1，其它值不变
    String expectedResult ="Current State\n" + "Beer: 0" + "\n" + "Orange Juice: 1" + "\n" + "5 Jiao: 2"+ "\n" + "1 Yuan: 1";
        assertEquals(expectedResult,saleMachine.currentState());
    }
    @Test
    public void testOperation2( ){
        saleMachine.operation(null,"5J");
        //投币5角，类型为空，啤酒剩余，期望值为各个资源值不变
        String expectedResult ="Current State\n" + "Beer: 1" + "\n" + "Orange Juice: 1" + "\n" + "5 Jiao: 1"+ "\n" + "1 Yuan: 1";
        assertEquals(expectedResult,saleMachine.currentState());
    }
    @Test
    public void testOperation3(){
        saleMachine.operation("Beer",null);
    //投币null，选择啤酒，啤酒剩余，运行错误
        String expectedResult ="Current State\n" + "Beer: 1" + "\n" + "Orange Juice: 1" + "\n" + "5 Jiao: 1"+ "\n" + "1 Yuan: 1";
        assertEquals(expectedResult,saleMachine.currentState());
    }    @Test
    public void testOperation4(){
        saleMachine.operation("Beer","1Y");
    //投币1元，选择啤酒，啤酒剩余，期望值为啤酒数-1,5角数-1，1元数+1，其它值不变
        String expectedResult ="Current State\n" + "Beer: 0" + "\n" + "Orange Juice: 1" + "\n" + "5 Jiao: 0"+ "\n" + "1 Yuan: 2";
        assertEquals(expectedResult,saleMachine.currentState());
    }    @Test
    public void testOperation5(){
        saleMachine.operation("Beer","2Y");
    //投币2元，选择啤酒，所有值不变
        String expectedResult ="Current State\n" + "Beer: 1" + "\n" + "Orange Juice: 1" + "\n" + "5 Jiao: 1"+ "\n" + "1 Yuan: 1";
        assertEquals(expectedResult,saleMachine.currentState());
    }    @Test
    public void testOperation6(){
        saleMachine.operation("OrangeJuice","1Y");
    //投币1元，选择橙汁，橙汁剩余，期望值为橙汁数-1,5角数+1，其它值不变
        String expectedResult ="Current State\n" + "Beer: 1" + "\n" + "Orange Juice: 0" + "\n" + "5 Jiao: 0"+ "\n" + "1 Yuan: 2";
        assertEquals(expectedResult,saleMachine.currentState());
    }
}
